package org.shilong.UI.party;

import org.shilong.UI.R;
import org.shilong.Utility.Loader.PartyListViewLoader;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.KeyEvent;
import android.widget.ListView;

public class BrandShowHistoryPartyFrame extends Activity {

	private ListView show_history_party_listview;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);

		setContentView(R.layout.new_layout_show_history_paries_content);

		listenBroadcast();

		initViews();
	}

	void initViews() {

		show_history_party_listview = (ListView) this
				.findViewById(R.id.show_history_party_listview);

		PartyListViewLoader loader = new PartyListViewLoader(
				show_history_party_listview, PartyListViewLoader.HISTORY_PARTY,
				this);

		loader.startTask();
	}

	void listenBroadcast() {

		IntentFilter filter = new IntentFilter(
				BrandPartyCenterFrame.ACTION_REFRESH_OLD_PAREIS_DATAS);

		registerReceiver(new RefreshDatasListener(), filter);

	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// TODO Auto-generated method stub

		if (keyCode == KeyEvent.KEYCODE_BACK) {

			if (PartyListViewLoader.myPopWindow != null) {
				if (PartyListViewLoader.myPopWindow.isShowing()) {

					PartyListViewLoader.myPopWindow.dismiss();

					return true;
				}
			}

		}
		return super.onKeyDown(keyCode, event);
	}

	private class RefreshDatasListener extends BroadcastReceiver {

		@Override
		public void onReceive(Context content, Intent intent) {
			// TODO Auto-generated method stub

			System.out.println( "开始获取历史聚会的功能..." );

			PartyListViewLoader loader = new PartyListViewLoader(
					show_history_party_listview,
					PartyListViewLoader.HISTORY_PARTY,
					BrandShowHistoryPartyFrame.this);

			loader.startTask();


		}
	}
}
